Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
To save the current project, select Save Project from the File menu, or click on the Save Project button on the toolbar. You’ll be prompted for a project name the first time you save it. Once a project name has been assigned, you will not be prompted further. TIP: The Freedom To Roam While you can keep all files for each project in a single folder, it isn’t necessary. In fact, Visual Basic’s strengths in reusing software components means that a project’s various modules will often be scattered here and there on your disk. ### Drawing Your Way To Success When Visual Basic first burst onto the scene, the feature that most amazed programmers was the way it allowed them to draw the program’s visual interface. No more writing long and complex code statements to display something on screen; just point, click, drag—and that’s all there was to it. Now that Visual Basic has been around a while and spawned a whole fleet of copycats, the idea of drawing a program’s interface has become accepted as the norm. Even so, I still think it’s fun. In this section, I’ll describe the tools and techniques Visual Basic provides for interface design. The controls you can use are represented by buttons in the Visual Basic toolbox. The picture on each button makes an attempt to represent the corresponding control. If you’re still not sure, just rest the mouse pointer over the button for a second or two: A tooltip will display next to the mouse pointer, describing the button’s control. I should mention that the controls displayed in the toolbox are only a small subset of what is available to you. When you start working, the default set of controls is displayed; these are called the intrinsic controls. Other controls are displayed in the toolbox only when you specify. I’ll explain how later in the chapter. ### Placing Controls On A Form When you start Visual Basic, a new project and a blank form will display in the Project window. Generally, you will just begin working with this form. If you need another blank form, simply select Add Form from the Project menu. While a Visual Basic program can contain multiple forms, we are going to limit ourselves to single-form projects for now. Visual Basic has two methods for placing controls on a form. If you double-click on a button in the toolbox, Visual Basic places a default-size control in the center of the form. This method is certainly quick—if you want a default-size control in the middle of your form. Otherwise, you’ll have to move and size the control after it has been placed on the form. The alternative, and I believe preferable, method is to click on the desired button and then drag to place the control on the form. As you drag, a small window opens showing the current dimensions of the control, its width and height. The units of measurement are twips, Visual Basic’s default unit of screen measurement. You’ll learn more about twips in a later chapter; for now, it’s enough to know that there are 1,440 twips in an inch. The click-and-drag method has the advantage of letting you place the control and set its position and size in one step, but you can use whichever technique you prefer. If you’ve placed a control on the form and want to place more controls of the same size and type, you can copy the original. Be sure that the control you want to copy is selected (small handles will appear around the edges of a selected control). If not, click on the control to select it. Then follow these steps: 1. Press Ctrl+C (or select Copy from the Edit menu). Visual Basic places a copy of the control on the Windows Clipboard. 2. Press Ctrl+V (or select Paste from the Edit menu). Visual Basic displays a dialog box asking if you want to create a control array. 3. Select No (learning about control arrays comes later). A duplicate control is placed on the form. 4. Repeat Steps 2 and 3 to place additional copies of the control on the form. Every control that you place on a form is given a default set of properties. As we will cover later in this chapter, modifying the properties of controls is a central part of designing your Visual Basic interface. Most importantly, each control is assigned a default Name property in a form that combines the name of the control type and a sequential number. For example, the first Text Box control that you place on a form is assigned the name Text1, the second one is Text2, and so on. TIP: Pop-Up Menus If you right-click on a control, a form, or just about anything on the Visual Basic screen, a pop-up menu will be displayed. The commands available on this menu are those relevant to the item clicked. You can access the same commands by using the regular menus at the top of the Visual Basic window, but the pop-up menus are often faster. Generally, I will not specifically mention pop-up menu commands, but you should know that they are available. ### Manipulating The Form The size and position of a form during program design is the size and position it will have when the final program runs (unless you modify the size or position in code). You can change the relative screen position that the form will have during program execution by pointing at the form’s icon in the form layout window at the lower right corner of the Visual Basic screen. When the mouse pointer changes to a four-headed arrow, drag the form icon to the desired screen position. To change the form’s size, click on it to select it (be sure to click between any controls that are on the form). The form will display eight handles on its corners and edges indicating that it is selected. Three of the handles will be dark; point at any one of them and drag the form to its new size. As you may have guessed, a form’s size and position are properties that can be changed by the program’s code when the program executes. Most Visual Basic programmers don’t worry about form position during design. If it is necessary to display the window at a specific position when the program runs, it is better done in code. This permits you to take the user’s screen resolution into account. Size is a different matter. Forms that contain a lot of controls—like most dialog boxes—will have their “proper” size dictated by their contents. If the form is too small, some of the controls may be hidden, whereas a form that is too large wastes valuable screen space. The usual approach is to adjust the size of the form visually during design, then set the form’s BorderStyle property to Fixed Single or Fixed Dialog, so the user will not be able to change its size while the program is running. In other forms where size is not critical, the BorderStyle property is usually left at the default setting of Sizable, so the user can adjust its size while the program is running.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.